<?php
/**
 * 处理用户更改本人信息的请求
 *
 * @author Judas <judasnow@gmail.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */
session_start();
require_once('path.php');
require_once(SOJ_ROOT.'/include/function/lib.php');
require_once('Log.php') ;

@$request = $_POST;

if ( empty( $_SESSION['username'] )){
	$_SESSION['fail_message'] = '非法操作,未登录用户尝试更改信息.';
	$_SESSION['url'] = '../index.php'; 
	header( 'Location:../message_handle/fail_handle.php' );
	exit ;
}else{
	$username = $_SESSION['username'];
}

try{
	$db = db_connect();
	$update_user_info_process = new update_user_info_process( $db , $username );

	foreach( $request as $key => $value ){
	
		if ( $key == 'nick' ){ 
			$update_user_info_process ->update_nick( $value ); 
		}
		if ( $key == 'sex' ){
			$update_user_info_process ->update_sex( $value );
		}
		if( $key == 'location' ){
			$update_user_info_process ->update_location( $value );
		}
		if( $key == 'motto' ){
			$update_user_info_process ->update_motto( $value );
		}
	}

	$_SESSION['success_message'] = '更改用户信息成功.';
	$_SESSION['url'] = '../index.php'; 
	header( 'Location:../message_handle/success_handle.php' );
	exit ;	
	
}catch(Exception $e){
	
	exception_handle( $e ) ;
}
